package com.xing.controller;


import com.xing.common.lang.Result;
import com.xing.model.Discuss;
import com.xing.service.DiscussService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * <p>
 *  评论控制器
 * </p>
 *
 * @author 柠檬有点甜
 * @since 2021-09-18
 */
@RestController
@RequestMapping("/discuss")
public class DiscussController {

    @Autowired
    DiscussService discussService;

    //主页面评论
    @GetMapping("/selectDiscuss")
    public Result selectDiscuss(){
        return discussService.selectDiscuss();
    }

    //详情评论
    @GetMapping("/selectDiscussById")
    public Result selectDiscussById(@PathParam("blogId") int blogId, @PathParam("pageId") int pageId){
        return discussService.selectDiscussById(blogId,pageId);
    }
    //发表评论
    @PostMapping("/setDiscuss")
    public Result setDiscuss(@RequestBody @Param("discuss") Discuss discuss){
        return discussService.updateDiscuss(discuss);
    }

    /**
     * 评论公共组件定时更新
     */
    @Scheduled(cron = "0 0 0/1 * * ?")//每隔一小时执行一次
    @GetMapping("/saveNewDiscuss")
    public void saveNewDiscuss(){
        discussService.saveNewDiscuss();
    }



}

